import java.util.Scanner;

/**
 * @author vivi
 * @description
 * @date 2024/5/18
 */
public class demo1 {
    public static boolean isPrim(Long num) {
        if (num < 2){
            return true;
        }else {
            for (int i = 2; i <= Math.sqrt(num); i++) {
                if (num % i == 0){
                    return false;
                }
            }
            return true;
        }
    }

    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        while (n-- != 0) {
            long x = scanner.nextLong(), y = scanner.nextLong();
            if ((isPrim(x) == true && y == 1) || (isPrim(y) == true && x == 1)) {
                System.out.println("YES");
            }else {
                System.out.println("NO");
            }
        }
    }

}
